home *** CD-ROM | disk | FTP | other *** search
- /* $Header: missing.c $
- *
- * Copyright (c) 1991, 1992 Matthias Neeracher
- *
- * You may distribute under the terms of either the GNU General Public
- * License or the Artistic License, as specified in the README file.
- *
- */
-
- #define SystemSevenOrLater 1
- #define RESOLVE_MAC_CONFLICTS
-
- #include "EXTERN.h"
- #include "perl.h"
- #include <Events.h>
-
- /* Calls that don't exist on the mac */
-
- /* Borrowed from msdos.c
- * Just pretend that everyone is a superuser
- */
- #define ROOT_UID 0
- #define ROOT_GID 0
- int
- getuid(void)
- {
- return ROOT_UID;
- }
-
- int
- geteuid(void)
- {
- return ROOT_UID;
- }
-
- int
- getgid(void)
- {
- return ROOT_GID;
- }
-
- int
- getegid(void)
- {
- return ROOT_GID;
- }
-
- int
- setuid(int uid)
- { return (uid==ROOT_UID?0:-1); }
-
- int
- setgid(int gid)
- { return (gid==ROOT_GID?0:-1); }
-
- execv()
- {
- fatal("execv() not implemented on the Macintosh");
- }
-
- execvp()
- {
- fatal("execvp() not implemented on the Macintosh");
- }
-
- utime()
- {
- fatal("utime() not implemented on the Macintosh");
- }
-
- chmod()
- {
- }
-
- kill()
- {
- fatal("kill() not implemented on the Macintosh");
- }
-
- sleep(int seconds)
- {
- long ticks = TickCount() + seconds*60;
-
- while (TickCount() < ticks)
- SpinPerlCursor(1);
- }
-
- do_aspawn()
- {
- fatal("do_aspawn() not implemented on the Macintosh");
- }
-
- do_spawn()
- {
- fatal("do_spawn() not implemented on the Macintosh");
- }
-
- char **environ;
-
- init_env(char ** env)
- {
- int envcnt = 0;
- int envsize = 0;
- int varlen;
- char * envpool;
-
- for (envcnt = 0; env[envcnt]; envcnt++) {
- varlen = strlen(env[envcnt]);
- envsize += varlen+strlen(env[envcnt]+varlen+1)+2;
- }
-
- environ = (char **) malloc((envcnt+1)*sizeof(char *));
- envpool = (char *) malloc(envsize);
-
- for (envcnt = 0; env[envcnt]; envcnt++) {
- environ[envcnt] = envpool;
- varlen = strlen(env[envcnt]);
- strcpy(envpool, env[envcnt]);
- envpool += varlen+1;
- envpool[-1] = '=';
- strcpy(envpool, env[envcnt]+varlen+1);
- envpool += strlen(env[envcnt]+varlen+1)+1;
- }
-
- environ[envcnt] = 0;
- }
-
- typedef struct PD {
- struct PD * next;
- FILE * tempFile;
- FSSpec pipeFile;
- char * execute;
- } PipeDescr, *PipeDescrPtr;
-
- static PipeDescrPtr pipes = nil;
- static Boolean sweeper = false;
-
- void sweep()
- {
- while (pipes)
- mypclose(pipes->tempFile);
- }
-
- FILE * mypopen(char * command, char * mode)
- {
- PipeDescrPtr pipe;
-
- New(666, pipe, 1, PipeDescr);
-
- if (!pipe)
- return NULL;
-
- if (FSpMakeTempFile(&pipe->pipeFile))
- goto failed;
- pipe->execute = nil;
-
- switch(*mode) {
- case 'r':
- if (SubLaunch(command, nil, &pipe->pipeFile, nil))
- goto delete;
- if (!(pipe->tempFile = fopen(FSp2FullPath(&pipe->pipeFile), "r")))
- goto delete;
- break;
- case 'w':
- New(667, pipe->execute, strlen(command)+1, char);
- if (!pipe->execute ||╩!(pipe->tempFile = fopen(FSp2FullPath(&pipe->pipeFile), "w")))
- goto delete;
- strcpy(pipe->execute, command);
- break;
- }
-
- pipe->next = pipes;
- pipes = pipe;
-
- if (!sweeper) {
- atexit(sweep);
- sweeper = true;
- }
-
- return pipe->tempFile;
- delete:
- if (pipe->execute)
- Safefree(pipe->execute);
- FSpDelete(&pipe->pipeFile);
- failed:
- Safefree(pipe);
-
- return NULL;
- }
-
- int mypclose(FILE * f)
- {
- OSErr err;
- PipeDescrPtr * prev;
- PipeDescrPtr pipe;
-
- for (prev = (PipeDescrPtr *) &pipes; pipe = *prev; prev = &pipe->next)
- if (pipe->tempFile == f)
- break;
-
- if (!pipe)
- return -1;
-
- *prev = pipe->next;
-
- fclose(f);
-
- if (pipe->execute)
- err = SubLaunch(pipe->execute, &pipe->pipeFile, nil, nil);
- else
- err = noErr;
-
- FSpDelete(&pipe->pipeFile);
- if (pipe->execute)
- Safefree(pipe->execute);
- Safefree(pipe);
-
- return err?-1:0;
- }
-